package world

import (
	"server/world/entity"
	"sync"
)

var Players = playerManager{}

//在线玩家管理

type playerManager struct {
	players map[string]*entity.Player
	mu      sync.RWMutex
}

func (this *playerManager) Add(p *entity.Player) {
	this.mu.Lock()
	defer this.mu.Unlock()
	this.players[p.Name] = p
}

func (this *playerManager) Get(name string) *entity.Player {
	this.mu.RLock()
	defer this.mu.RUnlock()
	return this.players[name]
}

func (this *playerManager) Remove(name string) {
	this.mu.Lock()
	defer this.mu.Unlock()
	delete(this.players, name)
}
